package cn.drenal.capcap.controller;

import cn.drenal.capcap.common.Response;
import cn.drenal.capcap.entity.Activity;
import cn.drenal.capcap.entity.vo.ActivityListVO;
import cn.drenal.capcap.service.ActivityService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 活动管理控制器
 */
@RestController
@RequestMapping("/activity")
@RequiredArgsConstructor
public class ActivityController {

    private final ActivityService activityService;

    /**
     * 分页查询活动列表
     *
     * @param current 当前页
     * @param size    每页大小
     * @param name    活动名称
     * @param status  活动状态
     * @return 分页数据
     */
    @GetMapping("/page")
    public Response<Page<ActivityListVO>> page(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) Integer status
    ) {
        return Response.success(activityService.page(current, size, name, status));
    }

    /**
     * 获取活动详情
     *
     * @param id 活动ID
     * @return 活动详情
     */
    @GetMapping("/{id}")
    public Response<Activity> getById(@PathVariable Long id) {
        return Response.success(activityService.getById(id));
    }

    /**
     * 新增活动
     *
     * @param activity 活动信息
     * @return 操作结果
     */
    @PostMapping
    public Response<Void> add(@RequestBody Activity activity) {
        activityService.save(activity);
        return Response.success();
    }

    /**
     * 更新活动
     *
     * @param id       活动ID
     * @param activity 活动信息
     * @return 操作结果
     */
    @PutMapping("/{id}")
    public Response<Void> update(@PathVariable Long id, @RequestBody Activity activity) {
        activity.setId(id);
        activityService.updateById(activity);
        return Response.success();
    }

    /**
     * 删除活动
     *
     * @param id 活动ID
     * @return 操作结果
     */
    @DeleteMapping("/{id}")
    public Response<Void> delete(@PathVariable Long id) {
        activityService.removeById(id);
        return Response.success();
    }
}